package j07object;

import java.io.*;
import java.util.ArrayList;

class Eye implements Serializable{
    String part1 = "晶状体";
}

class Cat implements Serializable {
    // 临时的，不会保存
    transient String name;
    int age;
//    Eye eye;


    public Cat(String name, int age) {
        this.name = name;
        this.age = age;
    }
}

public class J1 {
    public static void main(String[] args) throws Exception {
//        ObjectOutputStream fs = new ObjectOutputStream(
//                new FileOutputStream("_0905/src/j07object/1.txt")
//        );
//        fs.writeObject(new Cat("田园猫3",3));
//        fs.writeObject(new Cat("田园猫4",4));
//        fs.close();

        ObjectInputStream fs = new ObjectInputStream(
                new FileInputStream("_0905/src/j07object/1.txt")
        );
        while (true){
            Object obj = fs.readObject();
            System.out.println("obj = " + obj);
            if(obj==null)return;
            Cat c1 = (Cat)obj;
            System.out.println("c1 = " + c1);
            System.out.println("c1 = " + c1.name);
            System.out.println("c1 = " + c1.age);
        }
//        System.out.println(fs.readObject());
//        System.out.println(fs.readObject());
//        System.out.println(fs.readObject());

//        ArrayList

    }
}

class J2int{
    public static void main(String[] args) throws Exception {
//        ObjectOutputStream fs = new ObjectOutputStream(
//                new FileOutputStream("_0905/src/j07object/num.txt")
//        );
//        fs.writeInt(2);
//        fs.writeInt(7);
//        fs.close();

        //读取
        ObjectInputStream fs = new ObjectInputStream(
                new FileInputStream("_0905/src/j07object/num.txt")
        );

        System.out.println(fs.readInt());
        System.out.println(fs.readInt());
        System.out.println(fs.readInt());
    }
}